<template>

	<view>
		<view class="u-p-b-80">
			<view class="u-flex" v-if="siteList.length > 0" v-for="(res, index) in siteList" :key="res.id">


				<view class="item u-flex-7" @click="selectAddress(res)">
					<view class="top">
						<view class="name">{{ res.name }}</view>
						<view class="phone">{{ res.phone }}</view>
						<view class="tag">
							<text :class="{red:res.isDefault==1}">{{ res.isDefault==1 ? '默认': ''}}</text>
						</view>
					</view>
					<view class="bottom">
						{{res.address}}

					</view>
				</view>
				<view class="u-flex-1">
					<u-icon name="edit-pen" :size="40" color="#999999" @click="toUpdateAddSize(res)"></u-icon>
				</view>
			</view>
			<view v-else>
				<u-empty text="还没添加收货地址哟" mode="address"></u-empty>
			</view>
		</view>
		<!-- <view class="bottomFixed">
			<view class="addSite " @tap="toAddSite">
				
				<view class="add">
					<u-icon name="plus" color="#ffffff" class="icon" :size="30" ></u-icon>新建收货地址
				</view>
			</view>
		</view> -->
		<view class="bottomFixed u-flex u-p-15">
			<u-button type="warning" :ripple="true" shape="circle" @tap="toAddSite" size="medium">+ 新建收货地址</u-button>
		</view>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				siteList: [],
				isSelect: false
			};
		},
		onShow() {
			this.getData();
		},
		onLoad(val) {
			if (val != null) {
				this.isSelect = val['select']
			}

		},
		methods: {
			selectAddress(val) {

				if (this.isSelect != 'true') return
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.selectAddress = val; //修改上一页data里面的searchVal参数值为1211
				uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 1
				});

				
				},
				delAddress(id) {
						console.log(id)
					},
					toUpdateAddSize(option) {

						this.$u.route({
							url: '/pages/address/addSite',
							params: {
								addressInfo: this.$u.queryParams(option, false)
							}
						})
					},
					async getData() {

							const res = await this.$u.api.getAddressList(this.vuex_user.id)

							this.siteList = res
						},
						toAddSite() {
							uni.navigateTo({
								url: '/pages/address/addSite',

							});
						}
			}
		};
</script>

<style lang="scss" scoped>
	.item {
		padding: 40rpx 20rpx;

		.top {
			display: flex;
			font-weight: bold;
			font-size: 34rpx;

			.phone {
				margin-left: 60rpx;
			}

			.tag {
				display: flex;
				font-weight: normal;
				align-items: center;

				text {
					display: block;
					width: 60rpx;
					height: 34rpx;
					line-height: 34rpx;
					color: #ffffff;
					font-size: 20rpx;
					border-radius: 6rpx;
					text-align: center;
					margin-left: 30rpx;

				}

				.red {
					background-color: red
				}
			}
		}

		.bottom {
			display: flex;
			margin-top: 20rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #999999;
		}
	}

	.addSite {
		display: flex;
		justify-content: space-around;
		width: 600rpx;
		line-height: 100rpx;
		position: absolute;
		bottom: 30rpx;
		left: 80rpx;
		background-color: #ff9900;
		border-radius: 60rpx;
		font-size: 30rpx;
	
	.add {
			display: flex;
			align-items: center;
			color: #ffffff;

			.icon {
				margin-right: 10rpx;
			}
		}
	}

	.bottomFixed {
		position: fixed;
		left: 0;
		right: 0;
		background-color: #fff;
	}

	/*#ifdef H5*/
	.bottomFixed {
		bottom: 0rpx;
	}

	/*#endif*/
	/*#ifdef APP*/
	.bottomFixed {
		bottom: 0rpx;
	}
	
	/*#endif*/
	/*#ifdef MP-WEIXIN*/
	.bottomFixed {
		bottom: 0;
		
	}

	/*#endif*/
</style>
